#include<iostream>
#include<unistd.h>
#include<pthread.h>
#include<functional>
#include<cassert>

class Thread
{
    typedef std::function<void*(void*)> func_t;
public:
    Thread(func_t func,void*arg = nullptr)
    :_func(func),_arg(arg)
    {}

    void start()
    {
        int n = pthread_create(&_tid,nullptr,mystart,this);
        assert(n==0);
        (void)n;
    }

    void join(void** ret)
    {   
        int n = pthread_join(_tid,ret);
        assert(n==0);
        (void)n;
    }

private:
    static void* mystart(void* pt)
    {
        Thread* t=static_cast<Thread*>(pt);
        return t->_func(t->_arg);
    }
private:
    pthread_t _tid;
    func_t _func;
    void* _arg;
};